<?php 

include( "./admin/include/func.php");

//rovat lista
$rovatok = array ();
$db->sql = "SELECT hid,name,parent,sorrend FROM `hirdetek_hirdetes_rovatok` WHERE parent='0' ORDER BY `sorrend`";
$db->query();
//print $db->sql;
while ($row = mysql_fetch_assoc($db->rs)) $rovatok[]=$row;
for($i=0;$i<count($rovatok);$i++) {
	$db->sql = "SELECT hid,name,parent,sorrend FROM `hirdetek_hirdetes_rovatok` WHERE parent='".$rovatok[$i]['hid']."' ORDER BY `sorrend`";
	$db->query();
	while ($row = mysql_fetch_assoc($db->rs)) $rovatok[$i]['childs'][]=$row;					
}

$i = 1;
foreach ($rovatok as $rovat) {
	print $rovat['name']."<br />";
	$db->sql = "INSERT INTO rovat (id,nev,slug,`order`,parent) VALUES ('','".$rovat['name']."','".slug($rovat['name'])."','$i','0')";
	$db->query();
	$rid = mysql_insert_id();
	$j = 1;
	foreach ($rovat['childs'] as $child) {
		print $rovat['name']." - ".$child['name']."<br />";
		$db->sql = "INSERT INTO rovat (id,nev,slug,`order`,parent) VALUES ('','".$child['name']."','".slug($child['name'])."','$j','$rid')";
		$db->query();
		$j++;		
	}
	$i++;
}

?>
